package com.bwie.controller;


import com.bwie.pojo.TbBrand;
import com.bwie.pojo.TbUser;
import com.bwie.service.TUserService;
import com.bwie.service.TbBrandService;
import com.bwie.service.TbTypeService;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.utils.Result;
import com.bwie.vo.LoginFrom;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.parser.Token;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.naming.Name;
import java.util.List;

/**
 * @Author:Max
 * @Date: 2024/8/9 19:00
 * @Description
 **/
@RestController
@RequestMapping("/user/index")
@Slf4j
public class UserController {
    @Autowired
    TUserService tUserService;

    @Autowired
    TbBrandService tbBrandService;

    @Autowired
    TbTypeService tbTypeService;


    /**
     * 获取商品类型的树
     */
    @GetMapping("/getTypeTree")
    public Result getTypeTree() {
        return tbTypeService.getTypeTree();
    }


    /**
     * 获取商品类型的树（用于下拉框
     */
    @ApiOperation("下拉框商品类型的树")
    @PostMapping("/getTypeSelectTree")
    public Result getTypeSelectTree() {
        return tbTypeService.getTypeSelectTree();
    }



    /**
     * 登录
     */
    @PostMapping("/login")
    public Result login(@RequestBody @Validated LoginFrom login) {

        return tUserService.login(login);
    }

    /**
     * 导航侧边栏
     */
    @PostMapping("/getMenuTree/{userId}")
    public Result getMenuTree(@PathVariable(name = "userId") Integer userId) {
        return tUserService.getMenuTree(userId);
    }

    /**
     * 分页列表
     */
    @PostMapping("/selectList")
    public Result selecctList(@RequestBody PageInfoVo pageInfoVo) {
        return tUserService.selectList(pageInfoVo);
    }

    /**
     * 上传图片
     */
    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestPart("file") MultipartFile file) {
        return tUserService.uploadFile(file);
    }

    /**
     * 修改
     */
    @PostMapping("/updateFile")
    public Result updateFile(@RequestBody TbUser tbUser) {
        return tUserService.updateFile(tbUser);
    }

    /**
     * 分页获取品牌列表
     */
    @PostMapping("/getBrandList")
    public Result getBrandList(@RequestBody PageInfoVo pageInfoVo) {
        return tUserService.getBrandList(pageInfoVo);
    }

    /**
     * 单删
     */
    @PostMapping("/deleteById/{userId}")
    public Result deleteById(@PathVariable Integer userId) {
        return tUserService.deleteById(userId);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteAll")
    public Result deleteAll(@RequestBody List<TbUser> tbUserList) {
        return tUserService.deleteAll(tbUserList);
    }

    /**
     * 审核
     */
    @PostMapping("/checkUser")
    public Result checkUser(@RequestBody TbUser tbUser) {
        return tUserService.checkUser(tbUser);
    }

    /**
     * 添加
     */
    @PostMapping("/addBrand")
    public Result addBrand(@RequestBody TbBrand tbBrand) {
        return tUserService.addBrand(tbBrand);
    }


    /**
     * 修改品牌状态
     */
    @PostMapping("/updateBrandStatus")
    public Result updateBrandStatus(@RequestBody TbBrand tbBrand) {
        return tbBrandService.updateBrandStatus(tbBrand);
    }
}
